package de.mhus.lib.mandala;

import java.io.IOException;
import java.util.WeakHashMap;

import de.mhus.lib.core.activator.DefaultImplementation;
import de.mhus.lib.core.lang.MObject;
import de.mhus.lib.mandala.impl.DefaultUi;
import de.mhus.lib.mandala.impl.SetUi;

@DefaultImplementation(value=DefaultUi.class)
public abstract class Ui extends MObject {

	private WeakHashMap<String, Window> windows = new WeakHashMap<String, Window>();
	private String webPath;

	/**
	 * Return true if the tag should not end with an ENTER, like b, i strong or span.
	 * @return
	 */
	public abstract boolean isTextTag(String tagName);
	
	public abstract Response createResponse(Window forWindow, Object ... hints) throws IOException;
	
	public Window createWindow() {
		Window window = base(Window.class);
		if (window instanceof SetUi)
			((SetUi)window).setUi(this);
		add(window);
		return window;
	}

	public boolean isDebugFunctions() {
		return true;
	}
	
	public void add(Window window) {
		windows.put(window.getId(), window);
	}
	
	public void remove(Window window) {
		windows.remove(window.getId());
	}

	public void close() {
		
	}

	public Window getWindow(String id) {
		return windows.get(id);
	}

	public boolean isDebugRemoteCalls() {
		return true;
	}

	public void setWebPath(String requestURI) {
		this.webPath = requestURI;
	}
	
	public String getWebPath() {
		return webPath;
	}

}
